package com.mars.rabbitmq.normal;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author King
 * @create 2020/8/19 10:54
 */
@Slf4j
@Component
public class KingProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;



    public void send(String msg) {

        MessageProperties mp = new MessageProperties();
        Message message = new Message(msg.toString().getBytes(), mp);

        rabbitTemplate.setMandatory(true);
        CorrelationData correlationData = new CorrelationData("1234567890" + System.currentTimeMillis());
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE, RabbitMqConfig.ROUTING_KEY, message, correlationData);
        // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE, RabbitMqConfig.ROUTING_KEY, msg);
    }


}
